package org.jeecg.access.service.impl;

import lombok.extern.slf4j.Slf4j;
import org.jeecg.access.constant.PlatformType;
import org.jeecg.access.entity.AccountData;
import org.jeecg.access.entity.PlatformTotal;
import org.jeecg.access.entity.WorkData;
import org.jeecg.access.platform.mapper.KsCountMapper;
import org.jeecg.access.service.UnifiedPlatformService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * @description: todo
 * @author: taogang
 * @date: 2025/7/29 14:42
 */

@Slf4j
@Service
public class KsCountDataServiceImpl extends AbstractCountDataService implements UnifiedPlatformService {

    private final KsCountMapper ksCountMapper;

    @Autowired
    public KsCountDataServiceImpl(KsCountMapper ksCountMapper) {
        this.ksCountMapper = ksCountMapper;
    }

    @Override
    protected List<AccountData> queryAccountData() {
        try {
            return ksCountMapper.getDataList();
        } catch (Exception e) {
            log.error("获取快手账户数据失败", e);
            return new ArrayList<>();
        }
    }

    @Override
    protected List<WorkData> queryWorksData() {
        try {
            return ksCountMapper.getWorksList();
        } catch (Exception e) {
            log.error("获取快手作品数据失败", e);
            return new ArrayList<>();
        }
    }

    @Override
    public PlatformTotal getAccountTotal() {
        PlatformTotal platformTotal = new PlatformTotal();
        try {
            PlatformTotal result = ksCountMapper.getAccountNum();
            if (result != null) {
                platformTotal = result;
            }
            platformTotal.setPlatformSign(PlatformType.KWAI.getCode());
            platformTotal.setReadCount(0);
        } catch (Exception e) {
            log.error("获取快手账号统计数据失败", e);
        }
        return platformTotal;
    }

    @Override
    public AccountData getPlatformTotal() {
        AccountData result = new AccountData();
        try {
            AccountData data = ksCountMapper.getPlatformTotal();
            if (data != null) {
                result = data;
            }
        } catch (Exception e) {
            log.error("获取快手平台总计数据失败", e);
        }
        return result;
    }

    @Override
    public String getPlatformTypeCode() {
        return PlatformType.KWAI.getCode();
    }
}
